<?php

/*
 *
 *
 * This software has been made FREELY available by author for interest of the developers. 
 *      I hope this will help you in coding faster and robust php application
 *            You can modify and use it as you it suits you.
 *              Your comments, suggestions and corrections 
 *                          will be highly 
 *                           APPRECIATED. 
 *                                      Thanks, 
 *                                      Author
 * @author :   Roshan Budhathoki (contact@roshanbudhathoki.com);
 * @URL    :   <http://www.roshanbudhathoki.com>
 *
 */

class Params {
	function __construct() {
	}
	
	static function getParam($param, $htmlencode = false) {
		if ($param == "")
			return '';
		if (! isset ( $_REQUEST [$param] ))
			return '';
		
		$value = $_REQUEST [$param];
		if (! is_array ( $value )) {
			if ($htmlencode) {
				return htmlspecialchars ( stripslashes ( $value ), ENT_QUOTES );
			}
		}
		
		if (get_magic_quotes_gpc ()) {
			$value = strip_slashes_extended ( $value );
		}
		
		return ($value);
	}
	
	static function existParam($param) {
		if ($param == "")
			return false;
		if (! isset ( $_REQUEST [$param] ))
			return false;
		return true;
	}
	
	static function getFiles($param) {
		if (isset ( $_FILES [$param] )) {
			return ($_FILES [$param]);
		} else {
			return "";
		}
	}
	
	//$what = "post, get, cookie"
	static function getParamsAsArray($what = "") {
		switch ($what) {
			case ("get") :
				return (strip_slashes_extended ( $_GET ));
				break;
			case ("post") :
				return (strip_slashes_extended ( $_POST ));
				break;
			case ("cookie") :
				return ($_COOKIE);
				break;
			default :
				return (strip_slashes_extended ( $_REQUEST ));
				break;
		}
	}
	
	static function setParam($key, $value) {
		$_REQUEST [$key] = $value;
		$_GET [$key] = $value;
		$_POST [$key] = $value;
	}
	
	static function _view() {
		print_r ( self::getParamsAsArray () );
	}
}